package com.example.web.controller;

import com.example.web.entity.Goods;
import com.example.web.repository.GoodRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("/goods")
@Slf4j
public class GoodsController {

    @Autowired
    private GoodRepository goodRepository;


    @RequestMapping("/add")
    public ResponseEntity goodsAdd(Goods goods) {
        goodRepository.save(goods);
        return ResponseEntity.ok().build();
    }

    @RequestMapping("/update/{goodsId}")
    public ResponseEntity event(@PathVariable("goodsId")Long goodsId, Goods goods) {
        Goods one = goodRepository.getOne(goodsId);
        one.setPrice(goods.getPrice());
        goodRepository.saveAndFlush(one);
        return ResponseEntity.ok().build();
    }


}
